package com.sim.serialport.library.seria

import android.content.Context
import androidx.annotation.VisibleForTesting
import com.google.gson.Gson
import com.tencent.mmkv.MMKV
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class DataStoreImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    val gson: Gson
) : DataStore {
    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    val mmkv: MMKV?
    init {
        MMKV.initialize(context)
        mmkv = MMKV.defaultMMKV()
    }
    companion object {
        const val TEST_KEY = "test"
    }

    override var test: String?
        get() = mmkv?.decodeString(TEST_KEY)
        set(value) {
            mmkv?.encode(TEST_KEY, value)
        }
}